// rem
! function() {
	remLayout();

	function remLayout() {
		var w = document.documentElement.clientWidth;
		w = w > 768 ? 768 : w;
		w = w <= 320 ? 320 : w;
		document.documentElement.style.fontSize = w / 7.5 + 'px';
	}
	window.addEventListener('resize', function() {
		remLayout();
	}, false);
}();


// 公共ajax
function commonAjax(data, fn) {
    layer.open({type: 2});
	$.ajax({
		type: data.type,
		url: data.url,
		data: data.data,
		headers: {
			'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		},
		dataType: "json",
		success: function(msg) {
			if (msg.code == 200001) {
				fn(msg.data)
			}else if (msg.code == 401001) {
                window.location.replace("/")
			}else if (msg.code == 200402) {
                window.location.reload()
			} else {
                layer.open({
                    content: msg.message
                    ,skin: 'msg'
                    ,time: 1
                  });
			}
		},
        complete:function(){
            layer.closeAll()
        }
	})
}

//		获取url参数
function getUrlParams() {
	var str = location.href;
	var num = str.indexOf('?');
	var param = {};
	str = str.substr(num + 1);
	var arr = str.split('&');
	for (var i = 0; i < arr.length; i++) {
		num = arr[i].indexOf('=');
		if (num > 0) {
			var name = arr[i].substring(0, num);
			var value = arr[i].substr(num + 1);
			param[name] = decodeURI(value);
		}
	};
	return param;
};
